﻿
Partial Class Commodities_Show
    Inherits System.Web.UI.Page
    Dim c, connstr, conn, rs, rs1
    Function getText(ByVal tmp, ByVal s, ByVal e)
        'On Error Resume Next
        Dim String1, String2, arrstr, j
        String1 = s
        String2 = e
        Dim fbegin
        Dim fend
        fbegin = 1
        fend = 1
        Do
            fbegin = InStr(fbegin, tmp, String1)
            If fbegin = 0 Then Exit Function
            fend = InStr(fbegin, tmp, String2)
            arrstr = Mid(tmp, fbegin + Len(String1), fend - (fbegin + Len(String1)))
            getText = arrstr
            Exit Do
            fbegin = fend + Len(String2)
        Loop While True
    End Function
    Function getstr(ByVal iRemote)
        On Error Resume Next
        Dim xPost, sGet
        iRemote = iRemote
        xPost = SERVER.CreateObject("msxml2.serverxmlhttp") 'msxml2.serverxmlhttp
        xPost.Open("GET", iRemote, False)
        xPost.setrequestheader("referer", "http://taoke.alimama.com/spreader/search_auction.htm")
        xPost.Send()
        sGet = CreateObject("ADODB.Stream")
        sGet.Mode = 3
        sGet.Type = 1
        sGet.Open()
        sGet.Write(xPost.responseBody)
        sGet.Position = 0
        sGet.Type = 2
        sGet.Charset = "gb2312" ' "gb2312"
        getstr = sGet.ReadText
    End Function
    Function GetPid()
        rs.open("select *  from Config", conn, 1, 3)
        GetPid = rs("Pid").value
        rs.close()
    End Function
    Function GetTaoKeUrl()
        On Error Resume Next
        Dim code, cid
        cid = Request.QueryString("id")
        If Left(cid, 6) = "168861" Then
            cid = Right(cid, Len(cid) - 6)
            code = getstr("http://taoke.alimama.com/spreader/gen_auction_code.htm?auction_id=" & cid)

            GetTaoKeUrl = getText(code, "txt_urlcode"" name=""foroverflow"">", "</textarea>")
            GetTaoKeUrl = Replace(GetTaoKeUrl, "_10011550_", "_Pid_")
            Exit Function
        End If
        rs.open("select *  from commodity where cid='" & Int(Request.QueryString("id")) & "'", conn, 1, 3)
        If Not rs.eof Then
            code = getstr("http://taoke.alimama.com/spreader/gen_auction_code.htm?auction_id=" & rs("CID").value)
            If IsDBNull(rs("TaokeUrl").value) Then
                GetTaoKeUrl = getText(code, "txt_urlcode"" name=""foroverflow"">", "</textarea>")
                GetTaoKeUrl = Replace(GetTaoKeUrl, "10011550", "Pid")
                If InStr(GetTaoKeUrl, "t_1?") Then
                    rs("TaokeUrl").value = GetTaoKeUrl
                    If IsDBNull(rs("Goto").value) Then
                        rs("Goto").value = 1
                    Else
                        rs("Goto").value = rs("Goto").value + 1
                    End If
                    rs.update()
                End If
            Else
                If rs("TaokeUrl").value = "" Then
                    GetTaoKeUrl = getText(code, "txt_urlcode"" name=""foroverflow"">", "</textarea>")
                    GetTaoKeUrl = Replace(GetTaoKeUrl, "10011550", "Pid")
                    If InStr(GetTaoKeUrl, "t_1?") Then
                        rs("TaokeUrl").value = GetTaoKeUrl
                        If IsDBNull(rs("Goto").value) Then
                            rs("Goto").value = 1
                        Else
                            rs("Goto").value = rs("Goto").value + 1
                        End If
                        rs.update()
                    End If
                Else
                    If IsDBNull(rs("Goto").value) Then
                        rs("Goto").value = 1
                    Else
                        rs("Goto").value = rs("Goto").value + 1
                    End If
                    rs.update()
                    GetTaoKeUrl = rs("TaokeUrl").value
                End If
            End If

        Else
            GetTaoKeUrl = "Fail"
        End If
        rs.close()
    End Function
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        connstr = ConfigurationSettings.AppSettings("SQLConnString") & """" & Server.MapPath(".") & "\" & ConfigurationSettings.AppSettings("dbPath") & """"
        conn = Server.CreateObject("ADODB.Connection")
        conn.open(connstr)
        rs = Server.CreateObject("adodb.recordset")


        'Response.Write(tbCode)
        'Response.End()

    End Sub
End Class
